#include "PCVectorOpTest.h"
#include "wtype.h"
#include "PCVectorOp.h"
#include "common.h"
#include <string.h>

U31CodeFile vector_code_file;

void test_v_copy()
{
    int32_t in1[8] = {32769, -32768, 136777216, 582144, 544288, 6548576, 17894304, 20388608};
    int32_t in2[0] = {};

    VectorParam vp;
    vp.flag = V_FLAG_INTERRUPT | V_FLAG_INTERRUPT_0;
    vp.adr_in1 = in1;
    vp.num = 2;
    vp.in1_mode = V_IN_MODE_ARRAY;
    vp.adr_in2 = 0;
    vp.cmd_mode = V_NORMAL_MODE | V_SUM_MODE;
    vp.in1_type = V_IN_TYPE_32;
    vp.in2_en = V_IN2_DISABLE;
    vp.in2_mode = 0;
    vp.in2_type = 0;
    vp.out_type = V_OUT_TYPE_32;
    vp.adr_out = nullptr;

    int32_t case_num = 0; // 测试用例编号
    const char *instruction = get_instruction_from_func(__func__);
    // printf("instruction: %s\n", instruction);
    if (!instruction)
    {
        printf("get instruction from func failed!\n");
        return;
    }
    printf("%s_case%d:\n\t", instruction, case_num);
    v_instruction_process(v_copy, vp, gen_u31_code, vector_code_file, instruction, case_num);
    case_num++;
    vp.num = 4;
    printf("%s_case%d:\n\t", instruction, case_num);
    v_instruction_process(v_copy, vp, gen_u31_code, vector_code_file, instruction, case_num);

    return;
}
void test_v_abs()
{
    int32_t in1[8] = {32790, -32780, 136777216, 582144, 544288, 6548576, 17894304, 20388608};
    int32_t in2[0] = {};

    VectorParam vp;
    vp.flag = V_FLAG_INTERRUPT | V_FLAG_INTERRUPT_0;
    vp.adr_in1 = in1;
    vp.num = 2;
    vp.in1_mode = V_IN_MODE_ARRAY;
    vp.adr_in2 = 0;
    vp.cmd_mode = V_NORMAL_MODE | V_SUM_MODE;
    vp.in1_type = V_IN_TYPE_32;
    vp.in2_en = V_IN2_DISABLE;
    vp.in2_mode = 0;
    vp.in2_type = 0;
    vp.out_type = V_OUT_TYPE_32;
    vp.adr_out = nullptr;

    int32_t case_num = 0; // 测试用例编号
    const char *instruction = get_instruction_from_func(__func__);
    // printf("instruction: %s\n", instruction);
    if (!instruction)
    {
        printf("get instruction from func failed!\n");
        return;
    }
    printf("%s_case%d:\n\t", instruction, case_num);
    v_instruction_process(v_abs, vp, gen_u31_code, vector_code_file, instruction, case_num);
    case_num++;
    vp.num = 4;
    printf("%s_case%d:\n\t", instruction, case_num);
    v_instruction_process(v_abs, vp, gen_u31_code, vector_code_file, instruction, case_num);

    return;
}
void test_v_add()
{
    int32_t in1[8] = {32790, -32780, 136777216, 582144, 544288, 6548576, 17894304, 20388608};
    int32_t in2[8] = {32790, -32780, 136777216, 582144, 544288, 6548576, 17894304, 20388608};

    VectorParam vp;
    vp.flag = V_FLAG_INTERRUPT | V_FLAG_INTERRUPT_0;
    vp.adr_in1 = in1;
    vp.num = 2;
    vp.in1_mode = V_IN_MODE_ARRAY;
    vp.adr_in2 = in2;
    vp.cmd_mode = V_NORMAL_MODE | V_SUM_MODE;
    vp.in1_type = V_IN_TYPE_32;
    vp.in2_en = V_IN2_ENABLE;
    vp.in2_mode = V_IN_MODE_ARRAY;
    vp.in2_type = V_IN_TYPE_32;
    vp.out_type = V_OUT_TYPE_32;
    vp.adr_out = nullptr;

    int32_t case_num = 0; // 测试用例编号
    const char *instruction = get_instruction_from_func(__func__);
    // printf("instruction: %s\n", instruction);
    if (!instruction)
    {
        printf("get instruction from func failed!\n");
        return;
    }
    printf("%s_case%d:\n\t", instruction, case_num);
    v_instruction_process(v_add, vp, gen_u31_code, vector_code_file, instruction, case_num);
    case_num++;
    vp.num = 4;
    printf("%s_case%d:\n\t", instruction, case_num);
    v_instruction_process(v_add, vp, gen_u31_code, vector_code_file, instruction, case_num);

    return;
}
void pc_vector_instruction_test()
{
    creat_u31_project("u31_vector_test", vector_code_file);

    test_v_copy();
    test_v_abs();
    test_v_add();

    close_project(vector_code_file);
}
